<?PHP
  $current_page = "view_event_response.php";
  $page_type = "";
  require_once 'header.php';
?>
	<div id="page">
	  <div id="page-padding">
        <!-- start content -->	    
	    <div id="content">
	      <div id="content-padding">
            <h1>Sign Up Receipt</h1>
            <p>
			
			<?PHP
				if(isset($_SESSION['user_id']))
					$c_uid = trim($_SESSION['user_id']);

				//Find the creator's UserID of the Event to sign up for
				if (!empty($_POST['input_signup']))
					foreach ($_POST['input_signup'] as $input_signup){
						$c_eid = $input_signup;
						
						$sql = "select UserID, s_time from Event where EventID = '$c_eid'";
						$result_array = execute_sql_in_oracle($sql);
						$result = $result_array["flag"];
						$cursor = $result_array["cursor"];
						if(!$result){
							display_oracle_error_message($cursor);
							die("Event UserID query failed.");
						}
						$values = oci_fetch_array($cursor);
						$c_puid = $values[0];
						$c_stime = $values[1];
						oci_free_statement($cursor);
						$t_notifydate = "";

						//Generate the Signup_Date and Notify_Date
						if(isset($c_stime) and $c_stime != "") {
							$t_notifydate = date('d-M-y', strtotime(date(strtotime(time($c_stime))) . "-1 week"));
						}
						$t_currentdate = date('d-M-y', strtotime('now'));

						//Insert the user into Sign_UP
						$sql = "insert into SIGN_UP (UserID, PUserID, EventID, Signup_Date, Notify_Date) ".
						  " values ('$c_uid', '$c_puid', '$c_eid', '$t_currentdate' , '$t_notifydate')";
						$result_array = execute_sql_in_oracle($sql);
						$result = $result_array["flag"];
						
						if(!$result){
							$signup_error = $signup_error . "<br>Event '$c_eid' Signup failed.<br>";
							header("Location:view_event.php?signup_error=$signup_error");
						}
						else
						  echo("Congratulations! You've signed up for '$c_eid'.");
					}
			
			
			
			?>
			
			</p>
	      </div>
		</div>
	  <!-- end content --></div>
	  <div id="footer">
	    <div id="footer-pad">
	      <div class="line"></div>
		  <!-- footer and copyright notice -->
	      <p>Design by <a href="http://www.steves-templates.com">Steve's free website templates</a>.</p>
		  <!-- end footer and copyright notice -->
	    </div>
	  </div>
	</div>
  </body>
</html>